﻿using System.Linq;
using System.Web.Mvc;
using System.Collections.Generic;

using ASPNETMVCApplication.Code.Filters;
using ASPNETMVCApplication.Repositories;
using ASPNETMVCApplication.ActionServiceReference;
using ASPNETMVCApplication.Code.HtmlHelpers;
using ASPNETMVCApplication.Controllers;
using ASPNETWebApplication;
using ASPNETMVCApplication.Areas.Supp.Models;
using System.Web;

namespace ASPNETMVCApplication.Areas.Supp.Controllers
{
    public class TrafficController : Controller
    {
        private ITrafficRepository _trafficRepository;


        public TrafficController()
            : this(new TrafficRepository())
        {
        }

        /// <summary>
        /// Overloaded 'injectable' Constructor for ShopController.
        ///
        /// Pattern: Constructor Dependency Injection (DI).
        /// </summary>
        /// <param name="categoryRepository"></param>
        /// <param name="productRepository"></param>
        /// <param name="cartRepository"></param>
        public TrafficController(ITrafficRepository trafficRepository)
        {
            _trafficRepository = trafficRepository;
        }
        //
        // GET: /Supp/Traffic/
        public ActionResult TRegister()
        {
            
            return View();
        }
        //register account supplier
        [HttpPost]
        public ActionResult TRegister(TrafficModel trafficModel)
        {
            
            trafficModel.SupplierId = (int)Session["suppId"];
            HttpPostedFileBase postedFile = Request.Files["pictureUrl"];
            trafficModel.Picture = postedFile.FileName;
            trafficModel.TrafficTypeId = 1;
            trafficModel.DriverId = 1;
            trafficModel.L2NCPR = 0;
            trafficModel.L2RowNumber = 0;
            trafficModel.ServiceId = 1;
            trafficModel.Version = "0";
            var traffic = Mapper.FromModel(trafficModel);
            _trafficRepository.Insert(traffic);
            return View(trafficModel);
        }

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Supp/Traffic/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Supp/Traffic/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Supp/Traffic/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Supp/Traffic/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Supp/Traffic/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Supp/Traffic/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Supp/Traffic/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        
    }
}
